package com.woniu40.petai_user.mapper;

import com.woniu40.petai_user.entity.User;
import com.woniu40.petai_user.vo.UserVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;


import java.util.List;

@Repository
public interface UserMapper {
    int deleteByPrimaryKey(Integer userId);

    int insert(User user);

    User selectByPrimaryKey(Integer userId);

    List<User> selectAll();




    int updateByPrimaryKey(@Param(value = "userName") String userName,
                           @Param(value = "password") String password,
                           @Param(value = "userPhone") String userPhone,
                           @Param(value = "userEmail") String userEmail,
                           @Param(value = "sex") Integer sex,
                           @Param(value = "address") String address,
                           @Param(value = "avatar") String avatar,
                           @Param(value = "ismember") Integer ismember,
                           @Param(value = "userSign") String userSign,
                           @Param(value = "userId") Integer userId,
                           @Param(value = "userStatus") Integer userStatus ,
                           @Param(value = "errorCount") Integer errorCount );

    List<User> selectByIds(List<Integer> ids);

    List<User> selectUsers(Integer userId);

    @Select("select * from t_user where user_name=#{userName}")
    User selectUserByName(String userName);

    @Update("update t_user set error_count=error_count+1 where user_name=#{username}")
    int updateLoginErrorCount(String username);

    @Update("update t_user set user_status=0 where user_name=#{username}")
    int updateStatus(String username);
    @Update("update t_user set error_count=0 where user_name=#{username}")
    int updateErrorCount(String username);

    @Select("SELECT * FROM t_user WHERE user_id = #{value}")
    UserVo selectUserByUserId(Integer userId);

    List<User> selectAttentionUsers(@Param("attentionUserIds") List<Integer> attentionUserIds);
    @Update("update t_user set avatar=#{avatar} where user_id=#{userId}")
    int updateAvatar(@Param("userId") Integer userId, @Param("avatar") String avatar);


}